package hms.ReservationsModule;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*; 
import java.util.Date;
import java.text.*;

import javax.swing.*;

import hms.database.*;

/*This class created view for guest management view for managing guest information in GISM
 * includes fields for the following items:
 * 	-name
 * 	-address
 * 	-gender
 * 	-city
 *  -zip code
 *  -phone number
 *  -date of birth
 *  -reward membership info (called from Rewards sub-module)
 *  
 *  @author Edgar Onukwugha*/

public class GuestManagementView extends JDialog{
	
	protected JLabel firstNameLabel, lastNameLabel, addressLabel, phoneNumLabel, 
		birthDayLabel, birthMonthLabel, birthYearLabel;
	protected JTextField firstname, lastname, address1, address2, phoneNum;
	protected JTextField username;
	protected JPasswordField password;
	protected JComboBox birthDay, birthMonth, birthYear;
	
	JButton saveToDatabase;
	
	DAO d = new DAO("HMSDatabase", "db_files\\", true);
	
	//initialize choices used for JComboBoxes used to select date of birth
	String[] days = {
			"1","2","3", "4", "5", "6","7", "8", "9", "10", 
			"11", "12", "13", "14", "15","16","17","18","19","20",
			"21","22","23","24","25","26", "27","28","29","30",
			"31"
	};
	
	String[] months = {
		"January", "February", "March", "April", "May", "June", 
		"July", "August", "September", "October", "November", "December"
	};
	
	String[] years = {
		"1960","1961","1962","1963","1964","1965","1966","1967","1968","1969",
		"1970","1971","1972","1973","1974","1975","1976","1977","1978","1979",
		"1980","1981","1982","1983","1984","1985","1986","1987","1988","1989",
		"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999",
		"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009",
		"2010","2011","2012","2013",
	};
	
	//initializes view of Guest Management selection for GuestInfoView
	public JPanel initGuestManagementView(){
		//initialize all labels 
		firstNameLabel = new JLabel("First Name"); 
		lastNameLabel = new JLabel("Last Name");
		addressLabel = new JLabel("Address");
		phoneNumLabel = new JLabel("Phone Number");
		birthDayLabel = new JLabel("Day");
		birthMonthLabel = new JLabel("Month");
		birthYearLabel = new JLabel("Year");
		
		//initialize all textfields
		firstname = new JTextField(30);
		lastname = new JTextField(30);
		address1 = new JTextField(20);
		address2 = new JTextField(20);
		
		//initialize comboboxes used for calculating guest's date of birth
		birthDay = new JComboBox(days);
		birthMonth = new JComboBox(months);
		birthYear = new JComboBox(years);
		
		JPanel panel = new JPanel();
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		
		//add all components to panel
		panel.add(firstNameLabel);
		panel.add(firstname);
		panel.add(lastNameLabel);
		panel.add(lastname);
		panel.add(addressLabel);
		panel.add(address1);
		panel.add(address2);
		panel.add(phoneNumLabel);
		panel.add(phoneNum);
		panel.add(birthDayLabel);
		panel.add(birthDay);
		panel.add(birthMonthLabel);
		panel.add(birthMonth);
		panel.add(birthYearLabel);
		panel.add(birthYear);
		
		convertToDate();
		return panel;
	}
	
	//converts all date choices to string 
	public String convertToDate(){
		//gathers selected choices for day, month, year
		String day = (String)birthDay.getSelectedItem();
		String month = (String)birthMonth.getSelectedItem();
		String year = (String)birthYear.getSelectedItem();
		
		String date = day + "/" + month + "/" + year;
		
		return date;
	}
	
	//used to calculate the guest's age using 
	//the birth date in the database
	public void calculateGuestAge(){
		try{
			DateFormat format = new SimpleDateFormat("dd/mm/yyyy");
			Date guestBirthDate = (Date)format.parse(convertToDate());
			int age;
			String guestAge = new String();
			//return guestAge;
		}catch(ParseException pe){
			
		}
		
		
	}
	
	public void actionPerformed(ActionEvent e){
		//if user 
		if(e.getActionCommand() == "Save Changes"){}
	}
	
}
